import config from '@/config';

const { STORAGE_KEYS } = config;

export const saveAuth = (userInfo, token) => {
	if (userInfo) {
		uni.setStorageSync(STORAGE_KEYS.USER_INFO, userInfo);
	}
	if (token) {
		uni.setStorageSync(STORAGE_KEYS.TOKEN, token);
	}
};

export const getStoredUser = () => {
	return uni.getStorageSync(STORAGE_KEYS.USER_INFO) || null;
};

export const getToken = () => {
	return uni.getStorageSync(STORAGE_KEYS.TOKEN) || '';
};

export const clearAuth = () => {
	uni.removeStorageSync(STORAGE_KEYS.USER_INFO);
	uni.removeStorageSync(STORAGE_KEYS.TOKEN);
};

export const isLoggedIn = () => {
	return !!getStoredUser();
};

